#-*- coding:utf8 -*-
import os
import config
import tornado.httpserver
import tornado.ioloop
import tornado.autoreload
from app.member import MemberHandler
from app.question import QuestionHandler
from app.index import IndexHandler
from app.answer import AnswerHandler
from app.comet import CometHandler

application = tornado.web.Application([
    (r"/", IndexHandler),                                  
    (r"/login", IndexHandler, {'method': 'login'}),
    (r"/logout", IndexHandler, {'method': 'logout'}),
    (r"/dynamic", IndexHandler, {'method': 'dynamic'}),  
    (r"/last", IndexHandler, {'method': 'last'}),  
    (r"/get_dynamic_num", CometHandler, {'method': 'get_dynamic_num'}),
    (r"/apply", MemberHandler),
    (r"/questions", QuestionHandler, {'method': 'questions'}),
    (r"/question(.*)", QuestionHandler),
    (r"/answer(.*)", AnswerHandler),
	(r"/public/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__), "public")}),
], 
    cookie_secret = "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", 
    login_url = "/",
    template_path = config.settings['template'], 
    autoescape = None)

if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(application, xheaders = True)
    http_server.listen(80)
    tornado.autoreload.start(tornado.ioloop.IOLoop.instance(), 500)
    tornado.ioloop.IOLoop.instance().start()